﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef Button_h__
#define Button_h__

#include "AbstractButton.h"
#include "../base/Rect.h"
#include "Text.h"

namespace SkyEngine2d
{
	
	class Scale9Image;
	class EventMouse;
	
	/*!
	 \brief 按钮控件
	*/
	class SGE_API PushButton
		:public AbstractButton
	{
		UI_CLASS(PushButton)
	
	public:
		using MouseClickedCallback = std::function<void(EventMouse *)>;
	
	
		//! 析构
		~PushButton();
	
		//! 创建一个按钮控件
		/*!
		\param const WidgetSharedPtr & WidgetSharedPtr 父控件的指针
		\return ButtonSharedPtr
		\sa PushButtonSharedPtr create(const std::wstring & normal_picture,Rect  cap_insets = Rect::Zero,const WidgetSharedPtr & parent = nullptr)
		*/
		static PushButton* create(Widget* parent = nullptr);
	
		//! 创建一个按钮控件
		/*!
		\param const std::wstring & normal_picture  普通状态下的按钮展示图片路径
		\param Rect cap_insets	图片的可拉伸区域，参考 Scale9Image
		\param const WidgetSharedPtr & parent 父控件的指针
		\return PushButtonSharedPtr
		\sa PushButtonSharedPtr create(const WidgetSharedPtr & WidgetSharedPtr = nullptr)
		*/
		static PushButton* create(const std::wstring & normal_picture, const Rect &cap_insets = Rect::Zero, Widget* parent = nullptr);
	
		static PushButton* create(const SpriteFrameSharedPtr & sprite_frame, const Rect &cap_insets = Rect::Zero, Widget* parent = nullptr);
	
	
		//! 设置按钮被点击的监听回调
		/*!
		\param const MouseClickedCallback & call  监听器
		\return void
		*/
		void setClickedListener(const MouseClickedCallback & call);
	
	protected:
	
		PushButton(Widget* parent = nullptr);
	
		bool init();
		bool init(const std::wstring & normal_picture, const Rect & cap_insets);
		bool init(const SpriteFrameSharedPtr & sprite_frame, const Rect & cap_insets);
		virtual void onMouseReleaseEvent(EventMouse * event) override;
	
		//! 渲染 
		/*!
		\param Render * render 渲染接口
		\param const Matrix4X4 & transform 渲染矩阵
		\return void
		*/
		virtual void draw(IRender* render, const Matrix4X4& transform) override;
	
	
		virtual int getDefultWidth() const override;
	
	
		virtual int getDefultHeight() const override;
	
	
		virtual void onResizeEvent(EventResize * e) override;
	
		virtual void onMoveEvent(EventWidgetMove * e)override;
	
	private:
		MouseClickedCallback   m_clickedCall;
	};
}

#endif // Button_h__
